<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>垃圾管理</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__ADMIN_STATIC__/css/oksub.css">
  <script type="text/javascript" src="__STATIC__/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
  <blockquote class="layui-elem-quote">
    <p>垃圾清理(上传临时图片, 未使用图片, 缓存数据 等...)</p>
  </blockquote>

  <blockquote class="layui-elem-quote layui-quote-nm">
    <table class="layui-table">
      <colgroup>
        <col width="200">
        <col>
      </colgroup>
      <thead>
      <tr>
        <th>参数</th>
        <th>参数值</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody>
      <tr>
        <td>缓存数据</td>
        <td>{$cacheSize}</td>
        <td>
          <button class="layui-btn layui-btn-sm layui-btn-primary" id="cache_btn" >清空全部缓存</button>
          <button class="layui-btn layui-btn-sm layui-btn-primary" id="cache_console_btn" >清空控制台缓存</button>
          <button class="layui-btn layui-btn-sm layui-btn-primary" id="cache_menus_btn" >清空菜单缓存</button>
        </td>
      </tr>
      <tr>
        <td>垃圾文件</td>
        <td>{$gbSize}</td>
        <td><button class="layui-btn layui-btn-sm layui-btn-primary" id="clear_btn">清空垃圾</button></td>
      </tr>
      <tr>
        <td>关联文件</td>
        <td>{$relatedSize}</td>
        <td><button class="layui-btn layui-btn-sm layui-btn-primary" id="ruin_btn">恢复出厂</button></td>
      </tr>

      </tbody>
    </table>
  </blockquote>

</div>
<!--js逻辑-->
<script src="__STATIC__/lib/layui/layui.js"></script>
<script>
    layui.use(["element","okUtils",'okLayer','jquery'], function () {
        let $ = layui.jquery;
        let layer = layui.layer;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        okLoading.close();

        $('#cache_btn').on('click', function(){
            cache();
        });
        $('#cache_console_btn').on('click', function(){
            cacheConsole();
        });
        $('#cache_menus_btn').on('click', function(){
            cacheMenus();
        });
        $('#clear_btn').on('click', function(){
            clear();
        });
        $('#ruin_btn').on('click', function(){
            layer.msg('你是不是傻.',{
                icon: 7,
            });
        });



        /**
         * 清理缓存
         */
        function cache() {
            okLayer.confirm("确定要清空缓存吗？", function (index) {
                layer.close(index);
                okUtils.ajax("{:url('garbage/cache')}", "delete", {}, true).done(function (response) {
                    console.log(response);
                    layer.msg(response.msg,{
                        icon: 1,
                    }, function(){
                        window.location.reload();
                    });
                }).fail(function (error) {
                    console.log(error)
                });
            });
        }
        /**
         * 清理控制台缓存
         */
        function cacheConsole() {
            okLayer.confirm("确定要清理缓存吗？", function (index) {
                layer.close(index);
                okUtils.ajax("{:url('garbage/cacheConsole')}", "delete", {}, true).done(function (response) {
                    console.log(response);
                    layer.msg(response.msg,{
                        icon: 1,
                    }, function(){
                        window.location.reload();
                    });
                }).fail(function (error) {
                    console.log(error)
                });
            });
        }
        /**
         * 清理菜单缓存
         */
        function cacheMenus() {
            okLayer.confirm("确定要清理缓存吗？", function (index) {
                layer.close(index);
                okUtils.ajax("{:url('menu/clear')}", "post", {}, true).done(function (response) {
                    console.log(response);
                    layer.msg(response.msg,{
                        icon: 1,
                    }, function(){
                        window.location.reload();
                    });
                }).fail(function (error) {
                    console.log(error)
                });
            });
        }


        /**
         * 清理垃圾
         */
        function clear() {
            okLayer.confirm("确定要清空垃圾吗？", function (index) {
                layer.close(index);
                okUtils.ajax("{:url('garbage/clear')}", "delete", {}, true).done(function (response) {
                    console.log(response);
                    layer.msg(response.msg,{
                        icon: 1,
                    }, function(){
                        window.location.reload();
                    });
                }).fail(function (error) {
                    console.log(error)
                });
            });
        }



    })
</script>
</body>
</html>
